import { useIntersectionObserver } from '@vueuse/core'
import { ref } from 'vue'
// 封装的数据懒加载工具函数
export const useLazyData = api => {
  const target = ref(null)
  const list = ref([])
  const { stop } = useIntersectionObserver(target, async ([{ isIntersecting }]) => {
    if (isIntersecting) {
      stop()
      const data = await api()
      list.value = data.result
    }
  })
  return { target, list }
}
